"""
@File    :   out.py
@Time    :   2024/03/28 19:12:08
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   菜单相关序列化模型
"""

from datetime import datetime

from pydantic import BaseModel, Field, TypeAdapter

from src.business.admin.system.menu.enums import MenuTypeEnum
from src.schemas.out import BaseOutSchemaConfigMixin


class MenuCompleteOutSchema(BaseModel, BaseOutSchemaConfigMixin):
    """完整的菜单序列化模型"""

    id: int = Field(default=..., description="主键")
    name: str = Field(default=..., description="菜单名称")
    permission: str = Field(default=..., description="权限标识")
    type: MenuTypeEnum = Field(default=..., description="菜单类型")
    path: str = Field(default=..., description="路由地址")  # 外部地址以http(s)://开头
    icon: str = Field(default=..., description="菜单图标")
    component: str = Field(default=..., description="组件路径")
    component_name: str = Field(default=..., description="组件名称")
    visible: bool = Field(
        default=..., description="显示状态"
    )  # True显示 False隐藏 (选择隐藏时，路由将不会出现在侧边栏，但仍然可以访问)
    always_show: bool = Field(
        default=..., description="总是显示"
    )  # True是 False否 (选择不是时，当该菜单只有一个子菜单时，不展示自己，直接展示子菜单)
    keep_alive: bool = Field(
        default=..., description="缓存状态"
    )  # True缓存 False不缓存 (选择缓存时，则会被 `keep-alive` 缓存，必须填写「组件名称」字段)
    # 上级菜单ID(删除保护)
    parent_id: int = Field(default=..., description="上级菜单ID")
    status: bool = Field(default=..., description="状态")  # (True正常 False停用)
    remark: str = Field(default=..., description="备注")
    show_order: int = Field(default=..., description="显示顺序")
    is_system: bool = Field(
        default=..., description="是否系统级别菜单"
    )  # 系统级别菜单不可修改与删除
    create_datetime: datetime = Field(default=..., description="创建时间")
    update_datetime: datetime = Field(default=..., description="修改时间")
    creator_username: str = Field(default=..., description="创建者用户名")
    updater_username: str = Field(default=..., description="修改者用户名")


# 完整的菜单序列化列表模型
ListMenuCompleteOutSchema = TypeAdapter(list[MenuCompleteOutSchema])


class MenuSimpleOutSchema(BaseModel, BaseOutSchemaConfigMixin):
    """简易的菜单序列化模型"""

    id: int = Field(default=..., description="主键")
    name: str = Field(default=..., description="菜单名称")
    type: MenuTypeEnum = Field(default=..., description="菜单类型")
    parent_id: int = Field(default=..., description="上级菜单ID")


# 简易的菜单序列化列表模型
ListMenuSimpleOutSchema = TypeAdapter(list[MenuSimpleOutSchema])
